package com.china.utils;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.view.LayoutInflater;
import android.view.WindowManager.LayoutParams;
import android.widget.LinearLayout;
import com.china.osourcechina.R;


public class DialogUtils {

  /**
   * 显示默认的请求进度条
   * 
   * @param context
   * 
   * @param buttonCancelListener
   */
  public static Dialog ShowDefaultProDialog(Context context, final OnButtonCancelListener buttonCancelListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
    if (buttonCancelListener != null) {
      dialog.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface arg0) {
          if (buttonCancelListener != null) {
            dialog.dismiss();
            buttonCancelListener.onCancel();
          }
        }
      });
    } else {
      dialog.setCancelable(false);
    }
    LinearLayout layout = (LinearLayout) ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.pro_dialog_layout, null);
    int screenWidth = ScreenUtil.getScreenWidth(context);
    dialog.getWindow().setLayout(screenWidth * 1 / 3, LayoutParams.WRAP_CONTENT);
    dialog.getWindow().setContentView(layout);
    return dialog;
  }


  public static interface OnButtonEventListener {

    public void onConfirm();

    public void onCancel();
  }

  public static interface OnButtonCancelListener {

    public void onCancel();
  }

}
